#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx 
from core.ui.mainframe import MainFrame

from core.ui.imgs import TRIANGLE_BITMAP
from treemanager import TreeManager
import  wx.lib.anchors as anchors
import wx.lib.agw.aui as aui
from core.ide.themesmanager import ThemesManager
from core.ui.toolsbar import ToolsBarManager

class Panel(wx.Panel):
    def __init__(self):
        self.name="Project"
        wx.Panel.__init__(self, MainFrame(), -1, style=wx.TAB_TRAVERSAL | wx.CLIP_CHILDREN | wx.FULL_REPAINT_ON_RESIZE | wx.NO_BORDER)
        self.SetAutoLayout(True)
        #self._comboBox=wx.ComboBox(self, 500, "All", (150, -1),(100, -1), ["All"], wx.CB_DROPDOWN | wx.CB_READONLY)
        h=30#self._comboBox.GetSize()[1]
        #x = self._comboBox.GetPosition()[0]+self._comboBox.GetSize()[0]
        
        #b=wx.BitmapButton(self, -1, TRIANGLE_BITMAP(), (x+2, 1), (h,h))
        #self.Bind(wx.EVT_BUTTON, self.onClickMenu, b)
        
        #item = aui.AuiToolBarItem()        
        #item.SetKind(wx.ITEM_NORMAL)
        #item.SetId(-1)
        #item.SetLabel("Customize...")
        
        #self._tb=self.createToolsBar("[c]","build","play")
        #h=self._tb.GetSize()[1]
        self.tree=TreeManager(self)
        #self.tree.SetPosition((0,h))
        self._box=wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self._box)
        self._box.Add(self.tree,1,wx.EXPAND)
        #self.tree.SetConstraints(anchors.LayoutAnchors(self.tree, True, True, True, True))
    
    def createToolsBar(self,*tools):
        tb = aui.AuiToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
                         agwStyle=aui.AUI_TB_PLAIN_BACKGROUND)
        tb.SetToolBitmapSize(wx.Size(16, 16))
        for ind in tools:
            if ind=="|":
                tb.AddSeparator()
            if ind=="[c]":
                self._comboBox.Reparent(tb)
                tb.AddControl(self._comboBox)
            elif type(ind) is str:
                tb.AddSimpleTool(-1, "ind", ThemesManager().getDefaultTheme().getImage(ind,'icone_16'))
            #elif type(ind) is list and len(ind) and type(ind[0]) is str:
            #    choice = wx.ComboBox(tb, -1,ind[0], choices=ind, style=wx.CB_READONLY)
            #    tb.AddControl(choice)
            elif type(ind) is list:
                tool=wx.ID_HIGHEST+1
                tb.AddSimpleTool(tool, ind[0], ThemesManager().getDefaultTheme().getImage(ind[0],'icone_16'))
                tb.SetToolDropDown(tool, True)
                
        tb.Realize()
        return tb
        
    def openProject(self,project):
        #self._comboBox.Append("ProjectTest")
        self.tree.addProject(project)
        #self.tree.addMainSourcePath("ProjectTest", project.getBaseDir())
        #self.tree.setMainDocumentTree( project.getDocumentRoot())
        
    def createToolsBar2(self,*tools):
        tb = wx.ToolBar(self, -1, wx.DefaultPosition, wx.DefaultSize,
                         wx.TB_FLAT | wx.TB_NODIVIDER)
        tb.SetToolBitmapSize(wx.Size(16, 16))
        for ind in tools:
            if ind=="|":
                tb.AddSeparator()
            else:
                tb.AddLabelTool(-1, "Test", ThemesManager().getDefaultTheme().getImage(ind,'icone_16'))
        tb.Realize()  
        
        
    
    def onClickMenu(self, e):
        
        menu = wx.Menu()
        menu.Append(-1,'Test Project')
        menu.Append(-1,'Build Project')
        menu.Append(-1,'Debug Project')      
        menu.AppendSeparator()
        
        self.open=menu.Append(2002,'Open')
        menu.Append(-1,'Close')
        menu.AppendSeparator()
        menu.Append(-1,'Properties')
        self.PopupMenu(menu)
        menu.Destroy()